import React, { Component } from 'react'
import { AdvancedTable } from "components/index"
import Space from "components/space"
import Info from "components/info"
import { messages } from "share/common"
import { Button, Badge } from 'antd'
import httpFetch from "share/httpFetch"
import SlideFrame from "components/slide-frame"
import TypeAdvancePayment from "./type-advance-payment"
import Template from "components/UI/template"

const { Middle } = Template;

class TypeOfAdvancePayment extends Component {

  service = (page, size) => {
    return httpFetch.post(`/api/prepayment/type/query`, { page, size })
  };

  handleRule = record => {
    SlideFrame.open({
      content: TypeAdvancePayment,
      afterClose: flag => flag && this.tableRef.getList(),
      title: messages('finance-9.key88')/*预付款类型*/,
      params: { record }
    }, this)
  };

  columns = [
    { title: messages('finance-9.key89')/*层级*/, dataIndex: 'levelCode', render: () => messages('finance-9.key90')/*帐套*/ },
    { title: messages('finance-9.key91')/*所属组织*/, dataIndex: 'levelOrgName' },
    { title: messages('finance-9.key92')/*预付类型代码*/, dataIndex: 'prepaymentTypeCode' },
    { title: messages('finance-9.key93')/*预付类型名称*/, dataIndex: 'prepaymentTypeName' },
    { title: messages('common.column.status')/*状态*/, dataIndex: 'enabled', render: value => (
        <Badge
          status={value ? 'success' : 'error'}
          text={value ? messages('common.status.enable')/*启用*/ : messages('common.status.disable')/*禁用*/}
        />
      ) }
  ];

  render() {
    return (
      <Template>
        <Middle>
          <AdvancedTable.SimpleTable
            service={this.service}
            columns={this.columns}
            onRef={ref => this.tableRef = ref}
            rowKey={'id'}
            searchForm={[]}
            onRow={record => ({ onClick: () => this.handleRule(record) })}
          >
            <Space size='middle' direction='vertical'>
              <Info
                dataSource={{ description: messages('finance-9.key94')/*您可在此页面配置预付类型及预付类型的核销条件*/ }}
                attributes={[{
                  title: messages('finance-9.key95')/*设置说明*/, dataIndex: 'description', span: 24, widthFix: false
                }]}
              />
              <div>
                <Button type='primary' onClick={() => this.handleRule({})}>{messages('common.create')/*新建*/}</Button>
              </div>
            </Space>
          </AdvancedTable.SimpleTable>
        </Middle>
      </Template>
    )
  }

}

export default TypeOfAdvancePayment
